package com.api.shopapi.mapper;

import com.api.shopapi.entity.NursingRecordPosition;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface NursingRecordPositionMapper {


    @Insert("insert into nursing_record_position " +
            "(" +
            "NursingRecordPositionCode," +
            "NursingRecordCode," +
            "Lon," +
            "Lat," +
            "Address," +
            "CreateTime," +
            "IsAddLack," +
            "IsOvertime," +
            "Status" +
            ")values (" +
            "#{nursingRecordPosition.NursingRecordPositionCode} ," +
            "#{nursingRecordPosition.NursingRecordCode} ," +
            "#{nursingRecordPosition.Lon}," +
            "#{nursingRecordPosition.Lat}," +
            "#{nursingRecordPosition.Address}," +
            "#{nursingRecordPosition.CreateTime} ," +
            "#{nursingRecordPosition.IsAddLack} ," +
            "#{nursingRecordPosition.IsOvertime} ," +
            "#{nursingRecordPosition.Status} )")
    int insert(@Param("nursingRecordPosition") NursingRecordPosition nursingRecordPosition);


    @Delete("delete from nursing_record_position where nursingRecordPositionCode=#{nursingRecordPositionCode} ")
    int delete(@Param("nursingRecordCode") String nursingRecordPositionCode);

    @Update("update nursing_record_position" +
            " set" +
            " IsAddLack=#{nursingRecordPosition.IsAddLack}, " +
            " IsOvertime=#{nursingRecordPosition.IsOvertime}, " +
            " Status=#{nursingRecordPosition.Status} " +
            " where NursingRecordPositionCode=#{nursingRecordPosition.NursingRecordPositionCode} ")
    int update(@Param("nursingRecordPosition") NursingRecordPosition nursingRecordPosition);


    @Select("select  * from nursing_record_position where nursingRecordPositionCode=#{nursingRecordPositionCode} limit 1")
    NursingRecordPosition getByNursingRecordPositionCode(@Param("nursingRecordPositionCode") String nursingRecordPositionCode);


    @Select("select  * from nursing_record_position where nursingRecordCode=#{nursingRecordCode} order by CreateTime desc")
    List<NursingRecordPosition> listByNursingRecordCode(@Param("nursingRecordCode") String nursingRecordCode);


    @Select("select  * from nursing_record_position" +
            " where" +
            " IsOvertime=1 and IsAddLack=0 ")
    List<NursingRecordPosition> listNotAddLack();


    @Select("select  * from nursing_record_position" +
            " where" +
            " IsOvertime=0 and Status=0 and TIMESTAMPDIFF(MINUTE, createTime, now())>4 ")
    List<NursingRecordPosition> listOvertime();



}
